{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <span class="frm_input_box search append">
            <input type="text" id="js_keyword" placeholder="请输入用户名称" value="" class="frm_input" />
        </span>
<!--        <span>-->
<!--            <select id="class_id" class="form-control" style="width:130px">-->
<!--                <option value="">选择视频分类</option>-->
<!--                {volist name="class_list" id="vo"}-->
<!--                    <option value="{$vo.id}">{$vo.class_title}</option>-->
<!--                {/volist}-->
<!--            </select>-->
<!--        </span>-->
        <span>
            <select id="status" class="form-control" style="width:130px">
                <option value="">选择审核状态</option>
                <option value="0">未审核</option>
                <option value="1">通过</option>
                <option value="2">不通过</option>
            </select>
        </span>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="phone" placeholder="请输入用户账号" value="" class="frm_input" />
        </span>
        <span class="right">
            <!-- <button type="button" id="js_addAll" class="btn btn-primary"><i class="icon wb-plus"></i> 批量添加</button> -->
            <button type="button" id="js_addBtn" class="btn btn-primary"><i class="icon wb-plus"></i> 添加视频</button>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'username',width:100,align:'center'">用户名</th>
<!--        <th data-options="field:'class_title',width:100,align:'center'">视频分类</th>-->
        <th data-options="field:'user_id',width:100,align:'center'">账号</th>
        <th data-options="field:'video_title',width:100,align:'center'">视频标题</th>
        <th data-options="field:'video_img',width:100,align:'center',formatter:formatImg">视频封面</th>
        <th data-options="field:'video_path',width:100,align:'center',formatter:formatVideo">视频地址</th>
        <th data-options="field:'is_public',width:100,align:'center',formatter:formatType">是否发布</th>
        <th data-options="field:'status',width:100,align:'center',formatter:formatAuth">审核状态</th>
        </thead>
        <thead>
            <tr>
<!--                <th data-options="field:'video_view',width:120,align:'center',sortable: true">视频播放量</th>-->
                <th data-options="field:'praise_number',width:120,align:'center',sortable: true">视频点赞量</th>
                <th data-options="field:'create_time',width:150, align:'center'">创建时间</th>
                <th data-options="field:'update_time',width:150, align:'center'">更新时间</th>
<!--                <th data-options="field:'develop_time',width:150, align:'center'">置顶时间</th>-->
                <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        if(row['status'] == 0){
            html += '<button type="button" onclick="auth_status(' + row['id'] + ', 1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>通过</button>';
            html += '<button type="button" onclick="auth_status(' + row['id'] + ', 2)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>不通过</button>';
        }
        // html += '<button type="button" onclick="is_develop(' + row['id'] + ',1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>更新置顶</button>';
        // html += '<button type="button" onclick="is_develop(' + row['id'] + ',0)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>取消置顶</button>';
        // html += '<button type="button" onclick="addParise(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-plus"></i>点赞</button>';
        html += '</span>';
        return html;
    }

    //审核用户发布的商品
    function auth_status(id, status) {
        var text = '确认要通过吗?'
        if(status == 2){
            text = "确认驳回吗？"
        }
        confirm(text, function () {
            var url = getURL('auth_status');
            $.getJSON(url, {id: id, status:status}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    function formatImg(value) {
        if (value) {
            var html = '<div class="img_box" ><img style="height:35px; margin:5px" src="' + value + '" class="img" /></div>';
        } 
        return html;
    }
    $('body').on('click','.img',function(){
        src = $(this).attr('src');
        layer.open({
            type: 1,
            area: ['60%', '60%'],
            maxmin: false,
            content: '<div style="background:#000;width:100%;height:100%;display: table;text-align: center;vertical-align: middle;"><div style="display:table-cell;text-align: center;vertical-align: middle;"><img style="display: block;margin: auto;max-width: 1200px;max-height: 720px;" src="'+src+'"></div></div>',
        });
    })


    function formatVideo(value, row, index) {
        html = '';
        if(value!=null){
            html = '<video src="'+value+'" style="max-width:50px;max-height:20px;text-align: center" onclick="openVideo(\''+value+'\')"></video>';
        }
        return html;
    }

    function openVideo(path){
        var url = getURL('play')+'?path='+path;
        openBarWin('播放视频', 1000, 600, url, function () {
            reload();
        });
    }
    
    $(function () {
        $('#grid-table').datagrid({
            url: getURL('examineLoadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });
    
    $("#js_addBtn").click(function () {
        var url = getURL('edit');
        openBarWin('添加视频', 1000, 600, url, function () {
            reload();
        });
    });
    $("#js_addAll").click(function () {
        var url = getURL('add');
        openBarWin('批量添加点赞', 1000, 600, url, function () {
            reload();
        });
    });
    
    function formatAuth(value,row,index){
        var text = '<span style="color:red">未审核</span>';
        if(value == 1){
            text = '<span style="color:green">已审核</span>';
        }else if(value == 2){
            text = '<span style="color:#ff9b00">不通过</span>';
        }
        return text;
    }
    function formatType(value,row,index){
        var text = '<span style="color:green">下线</span>';
        if(value == 1){
            text = '<span style="color:red">上线</span>';
        }
        return text;
    }
    function formatOnline(value,row,index){
        var text = '<span style="color:green">在线</span>';
        if(value == 1){
            text = '<span style="color:red">离线</span>';
        }
        return text;
    }
    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 800, 600, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function addParise(id){
        var url = getURL('add', 'id=' + id);
        openBarWin('添加点赞', 1000, 600, url, function () {
            reload();
        });
    }

    function del(id) {
        confirm("确认要删除此视频吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    
    function appr(id) {
        confirm("确认通过审核？", function () {
            var url = getURL('changeStatus');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    function show_certificate(id) {
        var url = getURL('show_certificate', 'id=' + id);
        openBarWin('笔者资料', 1000, 800, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function cancel_appr(id) {
        var url = getURL('cancel_appr','id='+id);
        openBarWin('确认要拒绝此笔者通过审核吗?', 600, 300, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function is_develop(id,type) {
        if(type==1){
            $text = '确认要更新置顶吗?'
        }else {
            $text = '确认要取消置顶吗?'
        }
        confirm($text, function () {
            var url = getURL('is_develop');
            $.getJSON(url, {id: id, 'type': type}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        })

    }

    $("#js_search").click(function () {
        reload();
    });
    $("#class_id").change(function () {
        reload();
    });
    
    $("#check_state").change(function(){
        reload();
    })
    $("#type").change(function(){
        reload();
    })
    $("#status").change(function(){
        reload();
    })
    function reload() {
        var class_id = $("#class_id").val();
        var keyword = $("#js_keyword").val();
        var phone = $("#phone").val();
        var status = $("#status").val();
        var check_state  = $("#check_state").val();
        var type = $("#type").val();
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            class_id: class_id,
            status: status,
            phone: phone,
            check_state: check_state,
            type: type,
        });
    }

</script>
{/block}